package com.changgou.goods.service.impl;

import com.changgou.goods.dao.ParaMapper;
import com.changgou.goods.pojo.Spec;
import com.changgou.goods.service.ParaService;
import com.changgou.goods.pojo.Para;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;

@Service
public class ParaServiceImpl implements ParaService {

    @Autowired
    private ParaMapper paraMapper;

    /*
    添加规格列表
     */
    @Override
    public void add(Para para) {
        paraMapper.insertSelective(para);
    }

    /*
       删除规格列表
        */
    @Override
    public void delete(int id) {
        paraMapper.deleteByPrimaryKey(id);
    }

    /*
    规格列表分页查询
     */
    @Override
    public Page<Para> findall(int page, int size) {
        PageHelper.startPage(page,size);
        Page<Para> paras = (Page<Para>) paraMapper.selectAll();
        return paras;
    }

    /**
     * 根据模板id查询参数信息
     * @param id
     * @return
     */
    @Override
    public List<Para> findParaByTemId(int id) {
        Example example = new Example(Para.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("templateId",id);
        return paraMapper.selectByExample(example);
    }


}
